# -*- coding: UTF-8 -*-

import xeres
from ui import font

import interface
import convert

# text properties
class ColorApply(interface.sheet_property):
	def apply(self,pseudo,styles):
		print "color apply " , self.val
		return xeres.ARGB(self.val[0],self.val[1],self.val[2],self.val[3])

	def color(self,name,attr):
		# try cast color
		try:
			val = convert.convert_color(attr)
		except:
			print "Invalid value for '%s' property." %name
			return
		if self.val == None:
			if len(val) == 3:
				self.val = (255,val[0],val[1],val[2])
			else:
				self.val = val
		else:
			if len(val) == 3:
				self.val = (self.val[0],val[0],val[1],val[2])
			else:
				self.val = val

	def transparency(self,name,attr):
		# try cast transparency
		try:
			val = convert.color_val(attr)
		except:
			print "Invalid value for '%s' property." %name
			return
		if self.val == None:
			self.val = (val,255,255,255)
		else:
			self.val = (val,self.val[1],self.val[2],self.val[3])			
